<template>
  <div></div>
</template>

<script>
export default {
  name: 'listObject',
  data() {
    return {
      list: [],
    };
  },
  methods: {
    _findIndexByPredicate(predicate) {
      return this._.findIndex(this.list, predicate);
    },
    addItem(item, predicate) {
      let PisU = this._.isUndefined(predicate);
      if (!PisU) {
        let idx = this._findIndexByPredicate(predicate);
        if (idx > -1) return;
      }
      this.list.push(item);
    },
    removeItme(predicate) {
      if (this._.isUndefined(predicate)) return;
      let idx;
      if (this._.isNumber(predicate)) {
        if (this.list.length - 1 >= predicate) {
          idx = predicate;
        } else {
          idx = -1;
        }
      } else {
        idx = this._findIndexByPredicate(predicate);
      }
      if (idx === -1) return;
      this.tableList.splice(idx, 1);
    },
    clearList() {
      this.list.splice(0, this.list.length);
    },
    updataByPredicate({ predicate, key, value }) {
      let idx = this._findIndexByPredicate(predicate);
      if (idx === -1) return;
      this.$set(this.list[idx], key, value);
    },
  },
};
</script>

<style>
</style>